package com.gouda.core.service.impl.merchantManager;

import com.gouda.core.dao.MerchantBankDao;
import com.gouda.core.dto.merchantManage.MerchantBankDto;
import com.gouda.core.entity.MerchantBankEntity;
import com.gouda.core.service.BaseService;
import com.gouda.core.service.merchantManage.MerchantBankService;
import com.gouda.core.service.systemManage.MerchantUserService;
import com.themis.dto.BackendSystemUserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by KGL on 2015/12/7.
 */
@Service
public class MerchantBankServiceImpl extends BaseService implements MerchantBankService {
    @Autowired
    private MerchantUserService merchantUserService;
    @Autowired
    private MerchantBankDao merchantBankDao;

    @Override
    public boolean createMerchantBank(final MerchantBankDto merchantBankDto, final String loginUserId) {
        BackendSystemUserDto loginUser = merchantUserService.getUserById(loginUserId);
        MerchantBankEntity merchantBankEntity = ENTITY_FACTORY.generateDBEntity(MerchantBankEntity.class);
        merchantBankEntity.setBankCardCode(merchantBankDto.getBankCardCode());
        merchantBankEntity.setBankCardName(merchantBankDto.getBankCardName());
        merchantBankEntity.setBankId(merchantBankDto.getBankId());
        merchantBankEntity.setBankCardName(merchantBankDto.getBankCardName());
        merchantBankEntity.setBankName(merchantBankDto.getBankName());
        merchantBankEntity.setSubbranchBank(merchantBankDto.getSubbranchBank());
        merchantBankEntity.setMerchantId(loginUser.getBelongId());
        //TODO merchant bank card state
//        merchantBankEntity.setState();
        merchantBankEntity.setCreateTime(new Date());
        //TODO modify merchant register step

        return merchantBankDao.insert(merchantBankEntity);
    }
}
